#include <cassert>
#include <xscript/xprint.h>
#include <astree/xabstractsyntaxtreevalue.h>
#include <astree/xabstractsyntaxtreeprint.h>
#include <astree/xabstractsyntaxtreecreator_print.h>
#include <astree/xabstractsyntaxtreeparser.h>

bool XAbstractSyntaxTreeCreator_Print::isMatched(const XTokenBlock& tokens, uint32_t row, uint32_t col) {
    auto list = tokens.at(row).tokens;
    return list.at(0)->getString() == L"print";
}

std::shared_ptr<XAbstractSyntaxTree> XAbstractSyntaxTreeCreator_Print::create(const XTokenBlock& tokens, uint32_t row, uint32_t col, std::shared_ptr<XAbstractSyntaxTreeBuilder> builder) {
    skipToCol = 0;
    skipToRow ++;

    auto list = tokens.at(row).tokens;

    if (list.size() != 2) {
        XScriptExecutor::getInstance()->setError(XError::XError_Unsupported, list.at(0)->toString());
        return nullptr;
    }

    auto print = std::make_shared<XAbstractSyntaxTreePrint>(list.at(0));
    print->addChild(std::make_shared<XAbstractSyntaxTreeValue>(list.at(1)));
    return print;
}
